home *** CD-ROM | disk | FTP | other *** search
- Path: tick.cs.wm.edu!news
- From: mhagger@yellow.physics.wm.edu (Michael Haggerty)
- Newsgroups: comp.lang.c++
- Subject: Re: Inheritance and function signatures
- Date: 15 Mar 1996 20:54:31 -0500
- Organization: College of William and Mary
- Sender: mhagger@yellow.physics.wm.edu
- Message-ID: <x1lol1x0o8.fsf@yellow.physics.wm.edu>
- References: <MANOWAR.96Mar11132010@dilo.engin.umich.edu>
- <3146D380.2781@rchland.ibm.com>
- Reply-To: mhagger@mail.delos.physics.wm.edu
- NNTP-Posting-Host: yellow.physics.wm.edu
- In-reply-to: Philip Staite's message of Wed, 13 Mar 1996 07:54:08 -0600
- X-Newsreader: Gnus v5.1
-
- Hello,
-
- In article <3146D380.2781@rchland.ibm.com> Philip Staite
- <pstaite+@rchland.ibm.com> writes:
-
- > Basically within the scope of B the print(int,int) "captures" the name
- > print -- all references to print() go to it. Here's the FAQ that covers
- > this:
- >
- > ===========================================================================
- >
- > Q63: What's the meaning of, "Warning: Derived::f(int) hides
- > Base::f(float)"?
- >
- > It means you're going to die.
- >
- > Here's the mess you're in: if Derived declares a member function
- > named "f", and Base declares a member function named "f" with a
- > different signature (e.g., different parameter types and/or
- > constness), then the Base "f" is "hidden" rather than "overloaded"
- > or "overridden" (even if the Base "f" is virtual).
- >
- > Here's how you get out of the mess: Derived must redefine the Base
- > member function(s) that are hidden (even if they are non-virtual).
- > Normally this re-definition merely calls the appropriate Base member
- > function. E.g.,
- >
- > class Base {
- > public:
- > void f(int);
- > };
- >
- > class Derived : public Base {
- > public:
- > void f(double);
- > void f(int i) { Base::f(i); }
- > }; // ^^^^^^^^^^--- redefinition merely calls Base::f(int)
- >
- > ===========================================================================
-
- I have a question on this point.
-
- Is it sufficient to do the following:
-
- // example 1:
- class Base {
- public:
- void f(int);
- };
-
- class Derived : public Base {
- public:
- Base::f; // put Base::f in Derived's namespace
- void f(double); // add a new signature for f
- };
-
- ? If not, why not? It seems to me that this is a good and logical
- feature.
-
- The reason it would be nice is for the case of an abstract base class
- hierarchy:
-
- // example 2:
- class Base {
- public:
- virtual void f(int) = 0;
- };
-
- class Derived : public Base {
- public:
- virtual void f(double) = 0;
- void f(int i) { Base::f(i); } // OOPS!
- };
-
- As I understand it, example 2 is illegal since it attempts to call
- (non-virtually) Base::f(int), which doesn't exist at all. Or is there
- some twist in the rules that makes example 2 legal with the right
- behavior?
-
- I submit that there ought to be a way to do this...
-
- --Michael
-